//
//  NSMutableDictionary+Safe.m
//  mike2.0
//
//  Created by Mi on 15/9/17.
//  Copyright (c) 2015年 flychi. All rights reserved.
//

#import "NSMutableDictionary+Safe.h"

@implementation NSMutableDictionary (Safe)

- (void)safeSetObject:(id)anObject forKey:(id <NSCopying>)aKey {
    if(aKey && anObject) {
        [self setObject:anObject forKey:aKey];
    }
}

- (NSString *)stringObjectForKey:(id <NSCopying>)key {
    id anObject = [self objectForKey:key];
    if (key && anObject && [anObject isKindOfClass:[NSString class]]) {
        return anObject;
    }else{
        return @"";
    }
}

- (id)safeJsonObjectForKey:(id <NSCopying>)key {
    id anObject = [self objectForKey:key];
    if([anObject isKindOfClass:[NSNull class]]) {
        return (nil);
    }else{
        return (anObject);
    }
}

@end
